const express = require('express')
const app = express()
const qs = require('querystring')
app.use((req, res, next) => {
    //定义中间件的业务逻辑
    let str = ''
    //监听data事件
    req.on('data', (chunk) => {
        str += chunk
    })
    req.on('end', () => {
        // console.log(str);
        const body = qs.parse(str)
        console.log(body);
        req.body = body
    })
    next()
})
app.get('/user', (req, res) => {
    res.send(req.body)
})
app.post('/user', (req, res) => {
    res.send(req.body)
})
app.listen(8111, () => {
    console.log('express server running at localhost:8111');
})